package me.send.business.service.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.send.business.base.ErrorEntity;
import me.send.business.base.SendVariable;
import me.send.business.service.BaseService;
import me.send.business.service.mapper.CommaddressMapper;
import me.send.business.service.pojo.Commaddress;
import me.send.framework.util.HelperUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommaddressService extends BaseService{
	
	@Autowired
	private CommaddressMapper commaddressMapper;
	
	
	public ErrorEntity save(String devicenumber,Commaddress commaddress){
		//  判断 这个设备号 2015年6月1日17:33:44
		if (isDevicenumber(devicenumber)) {
			if (commaddress!=null) {
				commaddress.setCreatetime(HelperUtil.getCurrentDate());
				commaddressMapper.save(commaddress);
				return error_1000();
			}else {
				return error_1001();
			}
		}else {
			return error_1002();
		}
	}
	
	// 删除
	public ErrorEntity delete_id(String devicenumber,int addressid){
	//  判断 这个设备号 2015年6月1日17:33:44
		if (isDevicenumber(devicenumber)) {
			if (addressid!=0) {
				commaddressMapper.delete_id(addressid);
				return error_1000();
			}else
				return error_1006();
		}else {
			return error_1002();
		}
	}
	
	// 修改
	public ErrorEntity update_id(String devicenumber,Commaddress commaddress){
	//  判断 这个设备号 2015年6月1日17:33:44
		if (isDevicenumber(devicenumber)) {
			if (commaddress!=null) {
				commaddress.setUpdatetime(HelperUtil.getCurrentDate());
				commaddressMapper.update_userid(commaddress);
				return error_1000();
			}else {
				return error_1006();
			}
		}
		else {
			return error_1002();
		}
	}
	
	// 查询所有的地址
	public Map<String, Object> list_userid(String devicenumber,int userid){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(SendVariable.COMM_ERROR, "");
		map.put(SendVariable.COMMON_LIST, "");
	//  判断 这个设备号 2015年6月1日17:33:44
		if (isDevicenumber(devicenumber)) {
			if (userid!=0) {
				List<Commaddress> list = commaddressMapper.list_userid(userid);
				map.put(SendVariable.COMM_ERROR, error_1000());
				map.put(SendVariable.COMMON_LIST, list);
			}else{
				map.put(SendVariable.COMM_ERROR, error_1006());
			}
		}
		else {
			map.put(SendVariable.COMM_ERROR, error_1002());
		}
		return map;
	}
	

}
